﻿#pragma once

#include "../appender.h"

namespace log4lite {
	
	/// 控制台输出器
	/// 日志输出到控制台
	class ConsoleAppender : public Appender {
	public:

		ConsoleAppender(bool logToStdErr = false, bool immediateFlush = false) 
			: _logToStdErr(logToStdErr)
			, _immediateFlush(immediateFlush)
		{
			//
		}

		~ConsoleAppender()
		{
			destructorImlp();
		}

		virtual void close()
		{
			//
		}

	protected:
		virtual void append(const LogItem& item)
		{
			tostream& output = (_logToStdErr ? tcerr : tcout);
			_layout->formatAndAppend(output, item);
			if(_immediateFlush) {
				output.flush();
			}
		}

		
		bool _logToStdErr;
		/**
		 * Immediate flush means that the underlying output stream
		 * will be flushed at the end of each append operation.
		 */
		bool _immediateFlush;
	};

} // namespace log4lite
